home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15508 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  39 lines

  1. Path: galaxy.ucr.edu!csamaras
  2. From: csamaras@ucrengr.ucr.edu (Constantine Samares)
  3. Newsgroups: comp.lang.c++
  4. Subject: Dynamically allocating 2-dim arrays
  5. Date: 5 Apr 1996 22:41:22 GMT
  6. Organization: University of California, Riverside
  7. Message-ID: <4k47ii$ppa@galaxy.ucr.edu>
  8. NNTP-Posting-Host: spidey.ucr.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hello all,
  12.  
  13.    Does anyone out there know the "correct" way of dynamically allocating a
  14. 2-dimensional array in C++? This is the problem I'm running into:
  15.  
  16. -----------------------------------------
  17.      void main()
  18.      {
  19.         int xsize = 20, ysize = 25;
  20.         int** matrix;
  21.      
  22.         matrix = new int[xsize][ysize];
  23.      }
  24. -----------------------------------------
  25.  
  26. The compiler (g++) gloriously stops compiling with the following error:
  27.  
  28.      test.cc: In function `int main(...)':
  29.      test.cc:6: assignment to `int **' from `int (*)[1]'
  30.  
  31. It doesn't like "int* matrix", "int matrix[][]", or "int* matrix[]" either.
  32.                  -----------    --------------       -------------
  33.  
  34. Any suggestions?
  35.  
  36. Thanx,
  37.  
  38. -CT
  39.